// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Globalization;

namespace SnapObjects.Data
{
    public class ParameterNameGenerator
    {
        private readonly string _prefix;

        public ParameterNameGenerator(int count = 0)
        {
            this.Count = count;
            _prefix = String.Empty;
        }

        public ParameterNameGenerator(string prefix)
        {
            _prefix = prefix;
        }

        public virtual string GenerateNext()
        {
            return String.Format(CultureInfo.InvariantCulture, "{0}p{1}", _prefix, this.Count++);
        }

        /// <summary>
        ///     Generates the next unique parameter name.
        /// </summary>
        /// <returns> The generated name. </returns>
        public virtual string GenerateNext(bool originalParameter)
        {
            return String.Format(CultureInfo.InvariantCulture, originalParameter ? "{0}_p{1}" : "{0}p{1}", _prefix, this.Count++);
        }

        /// <summary>
        ///     Resets the generator, meaning it can reuse previously generated names.
        /// </summary>
        public virtual void Reset()
        {
            this.Count = 0;
        }

        public int Count { get; private set; }
    }
}
